package com.ymatou.iapi.fundstrategy.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fundstrategy.parameter.FundDimensionQueryBean;
import com.ymatou.iapi.fundstrategy.parameter.FundStrategyQueryInfo;
import com.ymatou.iapi.fundstrategy.service.FundDimensionQueryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtFundDimension;
import com.ymttest.database.sqlwapper.YmtFundDimensionWapper;
/**
*资金维度查询接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FundDimensionQuery{
	private static FundDimensionQueryBean funddimensionqueryBean;
	private static FundDimensionQueryCall funddimensionqueryCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("资金维度查询接口");
	}

	@Before
	public void caseUp() {
		funddimensionqueryBean=new FundDimensionQueryBean();
		funddimensionqueryCall=new FundDimensionQueryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(funddimensionqueryCall.getOpurl());
	}

	public static void  fundDQgetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
			String dataStr = funddimensionqueryCall.getReturnData();
			//返回报文断言			
			String fundDimensionList =  new JSONObject(dataStr).getString("FundDimensionList");
			Logger.verifyIsNull(fundDimensionList, "FundDimensionList为空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}
	
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FundDimensionQuery_001() {
		Logger.start(true,"资金维度查询");
		try {
			//TODO 补全case代码			
			ArrayList<String> fundDimensionNameList = new ArrayList<String>();
			fundDimensionNameList.add("商品类目");
			
			funddimensionqueryBean.setFundDimensionNameList(fundDimensionNameList);
			funddimensionqueryBean.setUserId(112233);
			funddimensionqueryBean.setUserLoginId("自动化测试");
			
			funddimensionqueryCall.setData(funddimensionqueryBean);
			funddimensionqueryCall.callService();	
			
			//获取返回报文的数据
			String dataStr = funddimensionqueryCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(true, Success, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");

			//SQL Ymt_FundDimension ymtfp库			
	    	YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();

	        //按照商品类目查询获取DimensionId
	        List<YmtFundDimension> ymtFundDimensionlist1 = ymtFundDimensionWapper.selectdimension("商品类目");
	        YmtFundDimension ymtFundDimension1 = ymtFundDimensionlist1.get(0);
	        //提取SQL&返回报文的Dimensionid，进行对比
	        String fundDimensionid1 = ymtFundDimension1.getDimensionId();
	        String dimensionId1 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getString("DimensionId");
	        Logger.verifyIsContains(fundDimensionid1, dimensionId1, "维度ID对比");
	        //提取SQL&返回报文的DimensionLimitType，进行对比
	        int fundDimensionLimitType1 = ymtFundDimension1.getDimensionLimitType();
	        int dimensionLimitType1 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getInt("DimensionLimitType");
	        Logger.verifyIsContains(fundDimensionLimitType1, dimensionLimitType1, "维度类型对比");
	        //提取SQL&返回报文的DimensionLimitType，进行对比
	        int fundDimensionStatus1 = ymtFundDimension1.getDimensionStatus();
	        int dimensionStatus1 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getInt("DimensionStatus");
	        Logger.verifyIsContains(fundDimensionStatus1, dimensionStatus1, "维度状态对比");
	        	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionQuery_002() {
		Logger.start(false,"资金维度名称不能为空");
		try {
			//TODO 补全case代码			
			funddimensionqueryBean.setFundDimensionNameList(null);
			funddimensionqueryBean.setUserId(112233);
			funddimensionqueryBean.setUserLoginId("自动化测试");		
			
			funddimensionqueryCall.setData(funddimensionqueryBean);
			funddimensionqueryCall.callService();
			
			//返回报文断言
			fundDQgetreturnerrcode("1022","资金维度名称不能为空");
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionQuery_003() {
		Logger.start(false,"用户id不能为空");
		try {
			//TODO 补全case代码			
			ArrayList<String> fundDimensionNameList = new ArrayList<String>();
			fundDimensionNameList.add("商品类目");
			fundDimensionNameList.add("商品价格");
			
			funddimensionqueryBean.setFundDimensionNameList(fundDimensionNameList);
			funddimensionqueryBean.setUserId(0);
			funddimensionqueryBean.setUserLoginId("自动化测试");
			
			funddimensionqueryCall.setData(funddimensionqueryBean);
			funddimensionqueryCall.callService();			
			
			//返回报文断言
			fundDQgetreturnerrcode("1006","用户id不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FundDimensionQuery_004() {
		Logger.start(true,"资金维度查询(商品价格)");
		try {
			//TODO 补全case代码			
			ArrayList<String> fundDimensionNameList = new ArrayList<String>();
			fundDimensionNameList.add("商品价格");
			
			funddimensionqueryBean.setFundDimensionNameList(fundDimensionNameList);
			funddimensionqueryBean.setUserId(112233);
			funddimensionqueryBean.setUserLoginId("自动化测试");
			
			funddimensionqueryCall.setData(funddimensionqueryBean);
			funddimensionqueryCall.callService();	
			
			//获取返回报文的数据
			String dataStr = funddimensionqueryCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(true, Success, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");

			//SQL Ymt_FundDimension ymtfp库			
	    	YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();	        	        
	        //按照商品价格查询获取DimensionId
	        List<YmtFundDimension> ymtFundDimensionlist2 = ymtFundDimensionWapper.selectdimension("商品价格");
	        YmtFundDimension ymtFundDimension2 = ymtFundDimensionlist2.get(0);
	        //提取SQL&返回报文的Dimensionid，进行对比
	        String fundDimensionid2 = ymtFundDimension2.getDimensionId();
	        String dimensionId2 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getString("DimensionId");
	        Logger.verifyIsContains(fundDimensionid2, dimensionId2, "维度ID对比");
	        //提取SQL&返回报文的DimensionLimitType，进行对比
	        int fundDimensionLimitType2 = ymtFundDimension2.getDimensionLimitType();
	        int dimensionLimitType2 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getInt("DimensionLimitType");
	        Logger.verifyIsContains(fundDimensionLimitType2, dimensionLimitType2, "维度类型对比");
	        //提取SQL&返回报文的DimensionLimitType，进行对比
	        int fundDimensionStatus2 = ymtFundDimension2.getDimensionStatus();
	        int dimensionStatus2 = new JSONObject(dataStr).getJSONArray("FundDimensionList").getJSONObject(0).getInt("DimensionStatus");
	        Logger.verifyIsContains(fundDimensionStatus2, dimensionStatus2, "维度状态对比");	        
				        	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

}